package com.dpj.Servlet;

import com.alibaba.fastjson.JSONObject;
import com.dpj.Service.BrandService;
import com.dpj.pojo.Brand;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet("/brandListServlet")
public class BrandListServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置响应数据的中文乱码
        response.setContentType("text/html;charset=utf-8");
        // 设置请求参数的中文乱码
        request.setCharacterEncoding("utf-8");
        BrandService brandService=new BrandService();
        List<Brand> brands=brandService.selectAll();
        String s = JSONObject.toJSONString(brands);
        response.getWriter().write(s);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
